using UnityEngine;
using UnityEngine.UI;
namespace NextMind.Examples.Steps
{
///
/// Implementation of an managed by the .
/// This step is used during the phases where it is needed to wait for the system to be ready (juste before calibration, or starting the demos).
///
public class WaitingForSystemReadyStep : AbstractStep
{
///
/// Should we automatically go to the next step when system is ready ?
///
[SerializeField]
private bool autoStartNextStep = false;
///
/// Moving part of the loading feedback.
///
[SerializeField]
private Image loadingBar = null;
///
/// Fixed part of the loading feedback.
///
[SerializeField]
private Image loadingBackground = null;
[SerializeField]
private Button nextButton = null;
///
/// The text element where to display the system-ready message.
///
[SerializeField]
private Text description = null;
///
/// The sentence to display when system is ready.
///
[SerializeField]
private string readyDescription = null;
private string originalDescription;
public override void OnEnterStep()
{
if (NeuroManager.Instance.IsReady())
{
OnSystemReady();
}
else
{
// Store the original description.
originalDescription = description.text;
// Block nextButton interaction.
nextButton.interactable = false;
ShowLoading(true);
}
}
public override void OnExitStep()
{
// Reset elements.
description.text = originalDescription;
nextButton.interactable = false;
// Stop loading animation.
ShowLoading(false);
}
public override void UpdateStep()
{
if (NeuroManager.Instance.IsReady())
{
OnSystemReady();
}
}
private void OnSystemReady()
{
if (autoStartNextStep)
{
stepsManager.OnClickOnNextStep(true);
}
else
{
ShowLoading(false);
description.text = readyDescription;
nextButton.interactable = true;
}
}
///
/// Start or stop the movement of the loading feedback.
///
/// The wanted loading state
private void ShowLoading(bool show)
{
Color green = loadingBar.color;
if (show)
{
green.a = 0.1f;
}
loadingBackground.color = green;
loadingBar.gameObject.SetActive(show);
}
///
public override bool GoToNextStepAllowed()
{
return !autoStartNextStep && NeuroManager.Instance.IsReady();
}
///
public override bool GoToPreviousStepAllowed()
{
return false;
}
}
}